classdef error_notification < handle
  % General set-up for and execution of error notification
  % Derived from handle
  % Constructor signature: oEN = error_notification(recipients), arg optional
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: < 2012-02-09
    
    properties
        mail_recip = {}; 
        mail_sender = 'dgol461@ecy.wa.gov'; 
        outgoingMailServ = '165.151.24.51';
        send = 1;
    end
    
    methods
        function oEN = error_notification(recipients)
            if nargin
                setpref('Internet', 'SMTP_Server', oEN.outgoingMailServ);
                setpref('Internet', 'E_mail', oEN.mail_sender);
                oEN.mail_recip = recipients;
            end
        end
    
        function notify(obj, app, msg, att, recipients)
            if nargin < 5
                recipients = obj.mail_recip;
            end
            if nargin < 4
                att = '';
            end
            
            if isempty(att)
                sendmail(recipients, [app 'error notification'], msg);
            else
                sendmail(recipients, [app 'error notification'], msg, att);
            end
        end
        
        function reportError(obj, app, siteID, report, tag)
            subj = ['Error in rt_data_getter for ' siteID ];
            msg = {subj, report, tag};
%             if ~strcmp(siteID, 'MCH01SR')
%                 obj.notify(app, msg)
%             end
        end
    end
        
end

